home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
X User Tools
/
X User Tools (O'Reilly and Associates)(1994).ISO
/
sun4c
/
archive
/
tcltk.z
/
tcltk
/
man
/
cat3
/
DString.3
< prev
next >
Wrap
Text File
|
1994-09-20
|
6KB
|
199 lines
Tcl_DStringInit(3) Tcl Library Procedures 7.0
_________________________________________________________________
NAME
Tcl_DStringInit, Tcl_DStringAppend,
Tcl_DStringAppendElement, Tcl_DStringStartSublist,
Tcl_DStringEndSublist, Tcl_DStringLength, Tcl_DStringValue,
Tcl_DStringTrunc, Tcl_DStringFree, Tcl_DStringResult - mani-
pulate dynamic strings
SYNOPSIS
#include <tcl.h>
Tcl_DStringInit(_d_s_P_t_r)
char *
Tcl_DStringAppend(_d_s_P_t_r, _s_t_r_i_n_g, _l_e_n_g_t_h)
char *
Tcl_DStringAppendElement(_d_s_P_t_r, _s_t_r_i_n_g)
Tcl_DStringStartSublist(_d_s_P_t_r)
Tcl_DStringEndSublist(_d_s_P_t_r)
int
Tcl_DStringLength(_d_s_P_t_r)
char *
Tcl_DStringValue(_d_s_P_t_r)
Tcl_DStringTrunc(_d_s_P_t_r, _n_e_w_L_e_n_g_t_h)
Tcl_DStringFree(_d_s_P_t_r)
Tcl_DStringResult(_i_n_t_e_r_p, _d_s_P_t_r)
ARGUMENTS
Tcl_DString *_d_s_P_t_r (in/out) Pointer to structure
that is used to manage a
dynamic string.
char *_s_t_r_i_n_g (in) Pointer to characters to
add to dynamic string.
int _l_e_n_g_t_h (in) Number of characters
from string to add to
dynamic string. If -1,
add all characters up to
null terminating charac-
ter.
int _n_e_w_L_e_n_g_t_h (in) New length for dynamic
Tcl 1
Tcl_DStringInit(3) Tcl Library Procedures 7.0
string, not including
null terminating charac-
ter.
_________________________________________________________________
DESCRIPTION
Dynamic strings provide a mechanism for building up arbi-
trarily long strings by gradually appending information. If
the dynamic string is short then there will be no memory
allocation overhead; as the string gets larger, additional
space will be allocated as needed.
Tcl_DStringInit initializes a dynamic string to zero length.
The Tcl_DString structure must have been allocated by the
caller. No assumptions are made about the current state of
the structure; anything already in it is discarded. If the
structure has been used previously, Tcl_DStringFree should
be called first to free up any memory allocated for the old
string.
Tcl_DStringAppend adds new information to a dynamic string,
allocating more memory for the string if needed. If _l_e_n_g_t_h
is less than zero then everything in _s_t_r_i_n_g is appended to
the dynamic string; otherwise _l_e_n_g_t_h specifies the number
of bytes to append. Tcl_DStringAppend returns a pointer to
the characters of the new string. The string can also be
retrieved from the _s_t_r_i_n_g field of the Tcl_DString struc-
ture.
Tcl_DStringAppendElement is similar to Tcl_DStringAppend
except that it doesn't take a _l_e_n_g_t_h argument (it appends
all of _s_t_r_i_n_g) and it converts the string to a proper list
element before appending. Tcl_DStringAppendElement adds a
separator space before the new list element unless the new
list element is the first in a list or sub-list (i.e. either
the current string is empty, or it contains the single char-
acter ``{'', or the last two characters of the current
string are `` {''). Tcl_DStringAppendElement returns a
pointer to the characters of the new string.
Tcl_DStringStartSublist and Tcl_DStringEndSublist can be
used to create nested lists. To append a list element that
is itself a sublist, first call Tcl_DStringStartSublist,
then call Tcl_DStringAppendElement for each of the elements
in the sublist, then call Tcl_DStringEndSublist to end the
sublist. Tcl_DStringStartSublist appends a space character
if needed, followed by an open brace;
Tcl_DStringAppendElement appends a close brace. Lists can
be nested to any depth.
Tcl 2
Tcl_DStringInit(3) Tcl Library Procedures 7.0
Tcl_DStringLength is a macro that returns the current length
of a dynamic string (not including the terminating null
character). Tcl_DStringValue is a macro that returns a
pointer to the current contents of a dynamic string.
Tcl_DStringTrunc truncates a dynamic string to a given
length. It has no effect if the string was already smaller
than _n_e_w_L_e_n_g_t_h. This procedure does not free up the
string's storage space, even if the string is truncated to
zero length, so Tcl_DStringFree will still need to be
called.
Tcl_DStringFree should be called when you're finished using
the string. It frees up any memory that was allocated for
the string and reinitializes the string's value to an empty
string.
Tcl_DStringResult sets the result of _i_n_t_e_r_p to the value of
the dynamic string given by _d_s_P_t_r. It does this by moving a
pointer from _d_s_P_t_r to _i_n_t_e_r_p->_r_e_s_u_l_t. This saves the cost
of allocating new memory and copying the string.
Tcl_DStringResult also reinitializes the dynamic string to
an empty string.
KEYWORDS
append, dynamic string, free, result
Tcl 3